package com.jinduplan.planmanager.ui.activity.clockin

//import com.baidu.mapapi.search.sug.OnGetSuggestionResultListener
//import com.baidu.mapapi.search.sug.SuggestionResult
//import com.baidu.mapapi.search.sug.SuggestionSearch
//import com.baidu.mapapi.search.sug.SuggestionSearchOption
import android.net.Uri
import com.cxz.kotlin.baselibs.base.BaseMvpTitleActivity
import com.cxz.kotlin.baselibs.base.lubanCompress
import com.cxz.kotlin.baselibs.utils.LogUtil
import com.cxz.kotlin.baselibs.utils.Preference
import com.cxz.kotlin.baselibs.utils.UserInfoUtil
import com.fphoenixcorneae.util.toast.ToastUtil
import com.jinduplan.planmanager.R
import com.jinduplan.planmanager.bean.BuildingNameBean
import com.jinduplan.planmanager.bean.ProjectUploadDetailBean
import com.jinduplan.planmanager.bean.UploadProjectLocation
import com.jinduplan.planmanager.constant.Constant
import com.jinduplan.planmanager.mvp.contract.ClockInContract
import com.jinduplan.planmanager.mvp.presenter.ClockInPresenter
import com.jinduplan.planmanager.utils.DateUtils
import com.jinduplan.planmanager.utils.FormatterEnum
import kotlinx.android.synthetic.main.activity_clock_in_comfir.*
import java.io.File


class ClockInComfirActivity : BaseMvpTitleActivity<ClockInContract.View, ClockInContract.Presenter>(),
    ClockInContract.View {

    var mProjectid = ""
    var mLongtitude  = ""
    var mLatititude = ""
    var mProjiectName: String by Preference(Constant.PROJECT_NAME, "")



    override fun attachChildLayoutRes(): Int {
        return R.layout.activity_clock_in_comfir
    }

    override fun createPresenter(): ClockInContract.Presenter {
        return ClockInPresenter()
    }

    override fun start() {
        val img = intent.extras?.getString(Constant.CLOCK_IN_IMG)
        val projectid = intent.extras?.getString(Constant.PROJECTID)
        val longtitude = intent.extras?.getString(Constant.LONGITUDE)
        val latititude = intent.extras?.getString(Constant.LATITUDE)
        mProjectid = projectid!!
        LogUtil.d("mLatitude:$latititude,mLongitude:$longtitude,mProjectId:$mProjectid")
        mLongtitude = longtitude.toString()
        mLatititude = latititude.toString()
        ivClockIn.setImageURI(Uri.fromFile(File(img)))
        tvComfir.setOnClickListener {
            img!!.lubanCompress(this,{
                mPresenter?.uploadClockInPic(it,0.toLong(),0.toLong(),mProjectid)
            })
        }
        val name = if (UserInfoUtil.fullname.isNullOrEmpty()) if(UserInfoUtil.nick_name.isNullOrEmpty()) UserInfoUtil.userName else UserInfoUtil.nick_name else UserInfoUtil.fullname
        tvName.setText(name)
        tvPhone.setText(UserInfoUtil.userName)
        tvDate.setText(DateUtils.formatToDay(FormatterEnum.YYYY_MM_DD))
        tvLocation.setText(mProjiectName)
    }

    override fun clockInSuccess() {
        ToastUtil.show("打卡成功")
        this.finish()
    }

    override fun uploadPicSuccess() {

    }

    override fun uploadPicSuccess(picUrl: String) {
        LogUtil.d("picUrl->$picUrl")

        mPresenter?.clockIn(picUrl, mLongtitude, mLatititude, mProjectid)

    }

    override fun postProjectLocationSuccess(uploadProjectLocation: UploadProjectLocation) {
    }

    override fun setProjectUploadDetailListData(projectData: BuildingNameBean) {

    }

}